var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[],
    mx_list:[],
    page:1,
    goods_id:0

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this 
    //店铺商品 goods_id=0 总的店铺商品
    Getglist(that, getApp().globalData.userid, 0)
    //核销明细集合  goods_id=0 总的店铺商品
    mx_list(that, getApp().globalData.userid,1,0)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this 

      //核销明细集合 下拉分页
      mx_list(that, getApp().globalData.userid, that.data.page, that.data.goods_id)

   
  },

  //点击单个核销明细集合
  danhexiao:function(event){
    var that = this
    var goods_id = event.currentTarget.dataset.id
    that.setData({
      goods_id: goods_id

    })
    //店铺商品
    Getglist(that, getApp().globalData.userid, goods_id)
    //核销明细集合
    mx_list(that, getApp().globalData.userid, 1, goods_id)
  }



})


var url = "https://17fx.com/weapp/Adminapi/gethexiaojilu.html";
//店铺商品
var Getglist = function (that, user_id, goods_id) {
  wx.request({
    url: url,
    data: {
      user_id: app.globalData.userid,
      goods_id: goods_id
    },
    header: {
      'content-type': 'application/json'
    },
    success: function (res) {
      console.log(res.data);
      that.setData({
        list: res.data
      })
    }
  })
}

var m_url = "https://17fx.com/weapp/Adminapi/gethexiaojilulist.html";
var page_size = 10;
//核销明细集合
var mx_list = function (that, user_id, page, goods_id) {
  wx.request({
    url: m_url,
    data: {
      user_id: app.globalData.userid,
      goods_id: goods_id,
      page: page,
      page_size: page_size
    },
    header: { 
      'content-type': 'application/json'
    },
    success: function (res) {
      console.log(res.data);
      if(page == 1){
        that.setData({
          mx_list: []
        })
      }
      if(res.data != null){
        var mx_list = that.data.mx_list;
        for (var i = 0; i < res.data.length; i++) {
          mx_list.push(res.data[i]);
        }
        that.setData({
          mx_list: mx_list,
          page: that.data.page + 1
        })
      }
      
    }
  })
}